{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='koi_common_nav'}
    <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">奖项设置</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                <input type="hidden" name="p_id" value="{$item['p_id']}"/>
                <input type="hidden" name="themeid" value="{$themeid}"/>
                <input type="hidden" id="p_status" name="p_status" value="{$item['status']}"/>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品简称</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="name" placeholder="" name="name" maxlength="5" value="{$item['name']}">
                        <span class="help-block">5个字以内 </span>
                    </div>
                </div>
                {if count($shangjia)>1}
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">绑定商家</label>
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select  class="form-control" name="sj_id">
                            <option value="0" {if empty($item['sj_id']) }selected="selected"{/if}>----------未选择----------</option>
                            {loop $shangjia $row}
                            <option value="{$row['id']}" {if $item['sj_id'] == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['name'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品描述</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="short_name" placeholder="" name="short_name" maxlength="80" value="{$item['short_name']}">
                        <span class="help-block">奖品描述  30字以内 </span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品库存</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="number" class="form-control"  id="qty" min="1" placeholder="" name="qty"  value="{$item['qty']}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品价值</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="number" class="form-control"  id="price" min="1" placeholder="" name="price"  value="{$item['price']}">
                        <span class="help-block">示例：800元 请填写800 </span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">奖项类型</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="is_lose" value="1" {if $item['is_lose']==1 } checked="checked"{/if} type="radio"> 必中奖项
                        </label>
                        <label class="radio-inline">
                            <input name="is_lose" value="2" {if $item['is_lose']==2 || empty($item['is_lose'])} checked="checked"{/if} type="radio">正常奖项
                        </label>
                        <span class="help-block">如</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">归属锦鲤：</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <select class="form-control" name="koi_id" id="koi_id">
                                <option value="0" {if empty($item['koi_id']) }selected="selected"{/if}>----------未选择----------</option>
                                {loop $lottery_koi  $val}
                                <option value="{$val['l_id']}" {if $item['koi_id'] == $val['l_id'] }selected="selected"{/if}>{$val['title']}</option>
                                {/loop}
                            </select>

                        </div>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>中奖概率</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="col-sm-4 col-xs-12 input-group">
                            <input class="form-control" type="number"  placeholder="" name="pr"  value="{php echo $item['pr']/100;}">
                            <span class="input-group-addon">%</span>
                        </div>
                        <span class="help-block">示例：0.01% 请填写数字 0.01</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品展示排序</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="col-sm-4 col-xs-12 input-group">
                            <input class="form-control" type="number" min="1" placeholder="1" maxlength="2" name="show_sort" id="show_sort"  value="{php echo $item['show_sort'];}">
                            <span class="input-group-addon">位</span>
                        </div>
                        <span class="help-block">排名靠前 数值越小 最小为1</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品小图</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_image('small_img',$item['small_img']);}
                        <span class="help-block">图片尺寸：200*200像素</span>
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">状态</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="status" value="2" {if $item['status']==2 || empty($item['status'])} checked="checked"{/if} type="radio"> 下架
                        </label>
                        <label class="radio-inline">
                            <input name="status" value="1" {if $item['status']==1} checked="checked"{/if} type="radio">上架
                        </label>
                        <span class="help-block">如：库存不足时，请先补充库存后再修改状态</span>
                    </div>
                </div>


                <div class="form-group" id="sub_upload" >
                    <div class="col-sm-12">
                        <input name="submit" onclick="addOrEditLtItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(
        function (){
        }
    );
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    //新增\修改 提交数据
    function addOrEditLtItem() {
        var p_status = $("#p_status").val();
        var qty = $("#qty").val();
        // if (qty==0){
        //     layer.msg('库存不能为0');
        //     return ;
        // }
        let postUrl = "{php echo createWebUrl('koi',array('op'=>'prize_update'));}";
        let success_redirect = "{php echo createWebUrl('koi',array('op'=>'prize_list'));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let res = e.message;
                let code = res.code;
                let msg = res.msg;
                if (code!=200){
                    layer.msg(msg)
                }else{
                    layer.msg(msg);
                    window.location.href = success_redirect;
                }

            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    // 修改、删除奖品
    function changeOrDelLttInfo(e) {
        let ltt_id = e.getAttribute("data-id");
        let type = e.getAttribute("data-type");
        let themeid = e.getAttribute("data-themeid");
        let redirectUrl = e.getAttribute("data-edit-url");
        let postUrl ="";
        if (type=='edit'){
            window.location.href = redirectUrl;
        }
        // if (type=='del'){
        //     postUrl = "{php echo createWebUrl('lt_delltitem');}";
        //     layer.msg('您确定删除该奖品吗？',{
        //         btn:['确定','取消'],
        //         yes:function (index) {
        //             $.ajax({
        //                 url:postUrl,
        //                 dataType:'json',
        //                 method:'post',
        //                 data: {ltt_id:ltt_id,themeid:themeid},
        //                 success:function (e) {
        //                     let res = e.message;
        //                     let code = res.code;
        //                     let msg = res.msg;
        //                     if (code!=200){
        //                         layer.msg(msg);
        //                     }else{
        //                         layer.msg(msg);
        //                         location.reload();
        //                     }
        //                 },
        //                 fail:function (err) {
        //                     console.log(err)
        //                 }
        //             });
        //         }
        //     });
        // }
    }
</script>
